<template>
  <div>
    <Form :model="searchFrom" :label-width="80">
      <Card style="margin-bottom: 10px;">
        币种类型:
        <Select v-model="searchFrom.biType" style="width:200px">
          <Option v-for="item in biTypeList" :value="item.index" :key="item.index">{{ item.name }}</Option>
        </Select>

        &nbsp;
        <Input placeholder="用户名或手机号码" v-model="searchFrom.mobileLike" style="width:200px"></Input>
        &nbsp;&nbsp;<Button type="primary" @click="getData(1)" icon="ios-search">{{$t('button.search')}}</Button>
      </Card>
    </Form>

    <Table border :data="tableData" :columns="tableColumns" stripe ref="selection" />
    <div style="margin:10px 0px;text-align: center;">
      <Page :total="dataCount" :current="searchFrom.page" @on-change="changePage"></Page>
    </div>
  </div>
</template>

<script>
  import {
    list
  } from "@/api/manager/userBiRecord";
  import {
    formatDate
  } from "@/libs/tools";
  export default {
    name: 'userBiRecord',
    props: {
      addUserId: {
        type: Number,
        default: null
      },
      orderId: {
        type: Number,
        default: null
      },
      biType: {
        type: Number
      }
    },
    data() {
      return {
        dataCount: 0,
        tableData: [],
        biGetTypeList: [],
        biTypeList: [],
        searchFrom: {
          page: 1,
          biType: this.biType
        },
      };
    },
    mounted: function() {},
    watch: {
      addUserId: function(value) {
        if (value) {
          this.searchFrom["addUserId"] = value;
          this.getData();
        }
      },
      orderId: function(value) {
        if (value) {
          this.searchFrom["orderId"] = value;
          this.getData();
        }
      },
    },
    computed: {
      tableColumns() {
        let that = this;
        return [{
            title: '序号',
            type: "index",
            width: 80,
            align: "center"
          },
          {
            title: this.$t("userBiRecordManager.biGetType"),
            align: "center",
            key: "biGetType",
            width:120,
            render: (h, params) => {
              let showName = "";
              for (let i = 0; i < this.biGetTypeList.length; i++) {
                if (this.biGetTypeList[i].index == params.row.biGetType) {
                  showName = this.biGetTypeList[i].name;
                  break;
                }
              }
              return h('div', showName);
            }
          },
          {
            title: "用户名",
            align: "center",
            key: "addUname"
          },
          {
            title: this.$t("userBiRecordManager.biNoBefore"),
            align: "center",
            key: "biNoBefore"

          },
          {
            title: this.$t("userBiRecordManager.biNo"),
            align: "center",
            width:250,
            key: "biNo",
            render: (h, params) => {
              let addOrPlus = "md-arrow-up";
              let color = "success";
              if (params.row.biChuOrRu == -1) {
                addOrPlus = "md-arrow-down";
                color = "error";
              }
              let bi = params.row.biNo;

              if (params.row.biType == 500 && params.row.biGetType == 1) {
                bi = "本金:" + params.row.map.orderMoney + " 收益:" + params.row.map.profitMoney
              }

              return h('Tag', {
                props: {
                  color: color
                },
              }, [
                h('Icon', {
                  props: {
                    type: addOrPlus
                  },
                }),
                h('span', {
                  style: {
                    marginLeft: '3px'
                  },
                }, bi),
              ], );
            }
          },
          {
            title: this.$t("userBiRecordManager.biNoAfter"),
            align: "center",
            key: "biNoAfter"
          },
          {
            title: "关联订单编号",
            align: "center",

            render: (h, params) => {
              let a = h("div", {},
                params.row.map.tradeIndex
              );
              let b = h("div", {}, '(' + params.row.map.addUserName + ')');
              return h("div", [a, b]);
            }
          },
          {
            title: this.$t("userBiRecordManager.addDate"),
            width: 120,
            align: "center",
            key: "addDate",
            render: (h, params) => {
              return h(
                "div",
                formatDate(new Date(params.row.addDate), "yyyy-MM-dd")
              );
            }
          },
        ];
      }
    },
    methods: {
      getData(page) {
        if (page) {
          this.searchFrom.page = page;
        }
        list(this.searchFrom).then(response => {
          const data = response.data;
          this.dataCount = data.data.dataCount;
          this.tableData = data.data.entityList;
          this.biGetTypeList = data.data.biGetTypeList;
          this.biTypeList = data.data.biTypeList;
        }).catch(error => {});
      },
      getRootUser(val) {
        let rootUser = val.map.rootUser;
        return rootUser;
      },
      changePage(page) {
        this.searchFrom.page = page;
        this.getData();
      },
    }
  };
</script>

<style>

</style>
